package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Hotel;
import cn.wolfcode.luowowo.article.query.HotelQuery;
import cn.wolfcode.luowowo.article.service.IHotelService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class HotelServiceImpl implements IHotelService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<Hotel> queryHotelsOnSale(Long destId) {
        Query query = new Query();
        query.addCriteria(new Criteria().andOperator(Criteria.where("destId").is(destId),Criteria.where("onsale").is(true)));
        return mongoTemplate.find(query,Hotel.class);
    }

    @Override
    public List<Hotel> listAll() {
        return mongoTemplate.findAll(Hotel.class);
    }
}
